package com.bungarus.busi;

import com.bungarus.codec.protobuf.MessageProtobuf;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap.KeySetView;

/**
 * Created by tang on 2018/11/18.
 */
public class DischargeQueue {
    private ConcurrentHashMap<Long, MessageProtobuf.Message> queue;

    public DischargeQueue(ConcurrentHashMap<Long, MessageProtobuf.Message> queue) {
        this.queue = queue;
    }

    public void addToQueue(MessageProtobuf.Message message) {
        queue.put(Long.valueOf(message.getHeader().getId()), message);
    }

    public MessageProtobuf.Message getFromQueue(Long key) {
        return queue.get(key);
    }

    public void removeFromQueue(Long msgId) {
        queue.remove(msgId);
    }

    public KeySetView<Long, MessageProtobuf.Message> keys() {
        return queue.keySet();
    }

    public int size() {
        return queue.size();
    }
}
